Pandas Series : Answer

Series :- one-dimensional array of indexed data


In [5]:
#Create a series 
import pandas as pd
series_1 = pd.Series([1,2,3,4])

In [6]:
# Left column is index and Right column is Data
series_1


Out[6]:
0    1
1    2
2    3
3    4
dtype: int64

In [7]:
series_1.index


Out[7]:
RangeIndex(start=0, stop=4, step=1)

In [8]:
series_1.values


Out[8]:
array([1, 2, 3, 4], dtype=int64)

In [9]:
series_1[1]


Out[9]:
2

In [10]:
series_1[1:]


Out[10]:
1    2
2    3
3    4
dtype: int64

In [11]:
series_1[:2]


Out[11]:
0    1
1    2
dtype: int64

In [12]:
# Here Index Assign naming to particulr data 
series_2 = pd.Series([1,2,3,4], index=['a','b','c','d'])

In [13]:
series_2


Out[13]:
a    1
b    2
c    3
d    4
dtype: int64

In [14]:
series_2[1]


Out[14]:
2

In [15]:
series_2['b']


Out[15]:
2

In [17]:
#Use Python Dictionary as series Series.
# A dictionary is a structure which maps arbitrary keys to a set of arbitrary values, and a series is a structure which 
# maps typed keys to a set of typed values.
#Create a Python Dictionary
python_dic = {'Nandan':'Big Data','Kundan':'Manager','Chandan':'Businees Man'}
# Assign Dictionary to Series 
people = pd.Series(python_dic)
# Check the Series 
people


Out[17]:
Chandan    Businees Man
Kundan          Manager
Nandan         Big Data
dtype: object

In [18]:
#Check type of data object
type(people)


Out[18]:
pandas.core.series.Series

In [19]:
people['Nandan']


Out[19]:
'Big Data'

In [21]:
people[2]


Out[21]:
'Big Data'

In [ ]: